package cn.datastructure.base1;

/**
 * @author summit
 * @since 2022/6/19 21:43
 */
public class FeibTest1 {

	/**
	 * 0 1 2 3 4 5 6
	 * 0 1 1 2 3 5 8
	 *
	 */



	public static int feib1(int n) {
		if (n == 0 || n == 1) {
			return n;
		}
		return feib1(n - 1) + feib1(n - 2);
	}

	public static int feib2(int n) {
		if (n == 0 || n == 1) {
			return n;
		}

		int first = 0;
		int second = 1;

		for (int i = 0; i < n-1; i++) {
			int sum = first + second;
			first = second;
			second = sum;
		}
		return second;
	}

	public static void main(String[] args) {
		System.out.println(feib1(6));

		System.out.println(feib2(6));
	}
}
